<!--
 * @Description: 
 * @Author: wangqi
 * @Date: 2021-07-03 13:37:16
 * @LastEditTime: 2021-07-07 10:14:36
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<!-- <script src="promise.js"></script> -->

<script>
    // let promise = new Promise((resolve, reject) => {
    //     let res =  Promise.resolve("ok");
    //     console.log(res instanceof Promise,"x")
    //     resolve(res);
    // });

    // promise.then((result) => {
    //     console.log(result, "result")
    //     let res = result instanceof Promise;
    //     console.log(res, "res")
    // }).catch((err) => {

    // });



    {


        function sleep(value) {
            return new Promise((resolve, reject) => {
                setTimeout(function () {  
                    resolve(value+"->")
                }, value)
            })
        };

        async function dbFuc() { //这里不需要 async
            let obj = [1, 2, 3, 4];
            // 可能得到错误结果
            // obj.forEach(async function (val, index) {
            //     console.log(index)
            //     await sleep(1000);
            // });


            for (let i = 0; i < obj.length; i++) {
                console.log(i)
                return "Xx"
                await sleep(1000);
            }

            // let arr = [1001, 1002, 1003, 1004];

            // const textPromise = arr.map(async (value) => {
            //     const response = await sleep(value);
            //     // console.log(response,"response ")
            //     return response;
            // });
            
            // // console.log(textPromise, "textPromise");
            
            // for(let val of textPromise){
            //     console.log(await val,"val")
            // }


        }

        dbFuc();

    }
</script>

</html>